home *** CD-ROM | disk | FTP | other *** search
/ Delphi 2.0 - Programmer's Utilities Power Pack / Delphi 2.0 Programmer's Utilities Power Pack.iso / s_to_z / tpack / retry.int < prev    next >
Encoding:
Text File  |  1996-09-15  |  3.6 KB  |  89 lines

  1. unit Retry;
  2.  
  3. interface
  4.  
  5. uses Classes, DsgnIntf, SysUtils, ExtCtrls, Forms, Dialogs, Controls
  6. , PasUtils
  7. , ErrorMsg;
  8.  
  9. type
  10.  
  11. {------------------------------------------------------------------------------}
  12. { TInterval                                                                    }
  13. {------------------------------------------------------------------------------}
  14.  
  15.   TInterval = class(TPersistent)
  16.   private
  17.     fInterval:Longint;
  18.     fRandom:Longint;
  19.     fProcessMessages: Boolean;
  20.     fOnWaitOver: TNotifyEvent;
  21.   protected
  22.     procedure   TimerEvent(Sender: TObject);
  23.     procedure   DoWaitOver(Sender: TObject); {virtual;}
  24.   public
  25.     constructor Create;
  26.     constructor CreateDelay(DelayMS:LongInt;WaitNow:Boolean);
  27.     constructor CreateRandomDelay(ShortMS,LongMS:LongInt;WaitNow:Boolean);
  28.     procedure   Execute;
  29.   published
  30.     property Interval: LongInt read fInterval write fInterval;
  31.     property RandomTime: LongInt read fRandom write fRandom;
  32.     property ProcessMessages: Boolean read fProcessMessages write fProcessMessages default True;
  33.     property OnWaitOver: TNotifyEvent read fOnWaitOver write fOnWaitOver;
  34.   end;
  35.  
  36.   TIntervalProperty = class(TClassProperty)
  37.   public
  38.     function GetAttributes: TPropertyAttributes; Override;
  39.   end;
  40.  
  41. {------------------------------------------------------------------------------}
  42. { TRetry                                                                       }
  43. {------------------------------------------------------------------------------}
  44.  
  45.   TRetryExceptionEvent =
  46.     procedure(Sender:TObject;E:Exception;var Action:TExceptionReAction) of object;
  47.  
  48.   TRetry = class(TPersistent)
  49.   private
  50.     fAskFirst: Boolean;   {should we ask to ok retries before retrying?}
  51.     fAutoRetry: Boolean;  {if true we will do fMaxRetries before giving up}
  52.     fAllowRetry: Boolean; {if the retry mechanism gives up, the user can allow more tries}
  53.     fMaxRetries: Integer; {number of retries allowed before asking for feedback}
  54.     fInterval: TInterval;
  55.     fOnAction: TNotifyEvent;
  56.     fCanIgnore: Boolean; {can an exception be ignored?}
  57.     fErrorAction: TExceptionReAction; {defaults to reAsk}
  58.     fErrorDialog: TErrorDialog; {can use a linked in error dialog before ours but after event}
  59.     fOnException: TRetryExceptionEvent;
  60.   protected
  61.     procedure RetryException(Sender:TObject;E:Exception;var Action:TExceptionReAction);
  62.   public
  63.     constructor Create;
  64.     constructor CreateAction(Action:TNotifyEvent;Exception:TRetryExceptionEvent);
  65.     destructor Destroy;
  66.     procedure Retry(Action:TNotifyEvent;Exception:TRetryExceptionEvent);
  67.     procedure RetryAction(Action:TNotifyEvent);
  68.     procedure Execute;
  69.   published
  70.     property Interval: TInterval read fInterval write fInterval;
  71.     property RetryAuto: Boolean read fAutoRetry write fAutoRetry default True;
  72.     property RetryMax:  Integer read FMaxRetries write FMaxRetries default 1;
  73.     property RetryAllow: Boolean read fAllowRetry write fAllowRetry default True;
  74.     property RetryAskFirst: Boolean read fAskFirst write fAskFirst default True;
  75.     property CanIgnore: Boolean read fCanIgnore write fCanIgnore;
  76.     property ErrorAction: TExceptionReAction read fErrorAction write fErrorAction;
  77.     property ErrorDialog: TErrorDialog read fErrorDialog write fErrorDialog;
  78.     property OnAction: TNotifyEvent read fOnAction write fOnAction;
  79.     property OnException: TRetryExceptionEvent read fOnException write fOnException;
  80.     end;
  81.  
  82.   TRetryProperty = class(TClassProperty)
  83.   public
  84.     function GetAttributes: TPropertyAttributes; Override;
  85.   end;
  86.  
  87. implementation
  88.  
  89.